//
//  AppointmentViewController.m
//  Doctor1.0
//
//  Created by mk on 15/11/5.
//  Copyright (c) 2015年 cocoa-mk. All rights reserved.
//

#import "AppointmentViewController.h"
#import "AppointmentListCell.h"
#import "ReservationData.h"
#import "AppointmentDetailsViewController.h"

#import "NewReservationListViewController.h"

@interface AppointmentViewController ()
{
    ReservationListData * listData;
}
@end

@implementation AppointmentViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //我的预约单
    titleLabel.text = @"预约单";
    listData = [[ReservationListData alloc]init];
    
    [self getListData];
    
    [indic startAnimating];
}

-(void)getListData
{
    NSString * strUrl = NullObjToString([gProjConfig.dicLocaldata objectForKey:@"bookingListUrl"]);
    
    listData.urlPath = [NSString stringWithFormat:@"%@?username=%@&token=%@",strUrl,[gProjConfig.dicUserData objectForKey:USER_tel],[gProjConfig.dicUserData objectForKey:USER_token]];
    listData.strDataKey = requestDataKey;
    //NSLog(@"===%@",listData.urlPath);
    [listData getLoadData:^(AFHTTPRequestOperation *operation, id responseObject)
    {
       //NSLog(@"====%@",responseObject);
       indic.hidden = YES;
       [indic stopAnimating];
       [tableMain reloadData];
        if (listData.dataArray.count>0)
        {
            imageNoData.hidden = YES;
            tableMain.hidden = NO;
        }else
        {
            imageNoData.hidden = NO;
            tableMain.hidden = YES;
        }
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         indic.hidden = YES;
         [indic stopAnimating];
         HUDShowRequestError(error.domain, self.view);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return listData.dataArray.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return 125;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellTableIdentifier = @"AppointmentListCellStr";
    
    AppointmentListCell *cell = (AppointmentListCell *)[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
    if (!cell)
    {
        cell = (AppointmentListCell *)[[[NSBundle mainBundle] loadNibNamed:@"AppointmentListCell" owner:self options:nil] objectAtIndex:0];
    }
    [cell fillDataWith:[listData.dataArray objectAtIndex:indexPath.row]];
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    AppointmentDetailsViewController * details = [[AppointmentDetailsViewController alloc]initWithNibName:@"AppointmentDetailsViewController" bundle:nil];
    details.reservationData = [listData.dataArray objectAtIndex:indexPath.row];
    [self.navigationController pushViewController:details animated:YES];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
